package valid

import (
	"git.oschina.net/fanbuchi/timemaker/models"
	"github.com/astaxie/beego/validation"
)

//response_type：表示授权类型，必选项，此处的值固定为"code"
//client_id：表示客户端的ID，必选项
//redirect_uri：表示重定向URI，可选项
//scope：表示申请的权限范围，可选项
//state：表示客户端的当前状态，可以指定任意值，认证服务器会原封不动地返回这个值。
func ValidClientsDetails(clientDetails *models.ClientDetails) (os models.ObjectStatus) {
	valid := validation.Validation{}
	os.Status = models.ParamError
	if v := valid.Required(clientDetails.ClientId, "client_Id"); !v.Ok {
		os.Desc = v.Error.Key + " " + v.Error.Message
	} else if v := valid.Required(clientDetails.ResponseType, "response_type"); !v.Ok {
		os.Desc = v.Error.Key + " " + v.Error.Message
	} else if v := valid.Required(clientDetails.Scope, "scope"); !v.Ok {
		os.Desc = v.Error.Key + " " + v.Error.Message
	} else {
		os.Status = models.Ok
	}
	return os
}

func ValidClient(client *models.Client) (os models.ObjectStatus) {
	valid := validation.Validation{}
	os.Status = models.ParamError
	if v := valid.Required(client.UserName, "user_name"); !v.Ok {
		os.Desc = v.Error.Key + " " + v.Error.Message
	} else if v := valid.Required(client.Password, "password"); !v.Ok {
		os.Desc = v.Error.Key + " " + v.Error.Message
	} else {
		os.Status = models.Ok
	}
	return os
}
